//
//  CommentSendViewCell.m
//  MSJD
//
//  Created by xiangbo on 2018/12/10.
//  Copyright © 2018 xiangbo. All rights reserved.
//

#import "MSCommentSendViewCell.h"

#define kDeleteBtnWidth 20

@implementation MSCommentSendViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self addImageView];
        [self addDeleteButton];
    }
    return self;
}

- (void)addImageView {
    UIImageView *imageView = [[UIImageView alloc]init];
    [self.contentView addSubview:imageView];
    _imageView = imageView;
}

- (void)addMoreButton {
    UIButton *moreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [moreBtn setImage:[UIImage imageNamed:@"sendMoreIcon"] forState:UIControlStateNormal];
    [moreBtn addTarget:self action:@selector(moreAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:moreBtn];
    _moreBtn = moreBtn;
}

- (void)addDeleteButton {
    UIButton *deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [deleteBtn setImage:[UIImage imageNamed:@"Add_Pictures_DeleteiCON"] forState:UIControlStateNormal];
    [deleteBtn addTarget:self action:@selector(deleteAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:deleteBtn];
    _deleteBtn = deleteBtn;
}

- (void)addVideoImageView {
    UIImageView *imageView = [[UIImageView alloc]init];
    imageView.image = [UIImage imageNamed:@"comment_Play"];
    imageView.hidden = YES;
    [self.contentView addSubview:imageView];
    _videoImageView = imageView;
}

- (void)deleteAction:(UIButton *)button {
    if ([_delegate respondsToSelector:@selector(commentSendViewCell:didDeleteIndex:)]) {
        [_delegate commentSendViewCell:self didDeleteIndex:button.tag];
    }
}

- (void)moreAction:(UIButton *)button {
    if ([_delegate respondsToSelector:@selector(commentSendViewCellDidClickedMoreAction:)]) {
        [_delegate commentSendViewCellDidClickedMoreAction:self];
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    _deleteBtn.frame = CGRectMake(CGRectGetWidth(self.contentView.frame)-kDeleteBtnWidth-2, 2, kDeleteBtnWidth, kDeleteBtnWidth);
    _imageView.frame = CGRectMake(0, 0, CGRectGetWidth(self.contentView.frame), CGRectGetHeight(self.contentView.frame));
//    _videoImageView.frame = CGRectMake((CGRectGetWidth(self.contentView.frame) - 20 -10)/2, (CGRectGetHeight(self.contentView.frame)-20+10)/2, 20, 20);
//    _moreBtn.frame = _imageView.frame;
}

@end
